package com.fit.spring.boot.proxy.extension.interceptor;

import java.lang.reflect.Method;
import java.util.Map;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 扩展拦截器
 * @author hcl
 *
 */
public class ProxyExtensionMethodInterceptor implements MethodInterceptor {
	/**
	 * 方法拦截器
	 */
	private Map<Method, InterceptorChain> methodInterceptorChain;
	
	/**
	 * 构造方法初始化设置方法拦截器
	 * @param methodInterceptors
	 */
	public ProxyExtensionMethodInterceptor(Map<Method, InterceptorChain> methodInterceptorChain){
		this.methodInterceptorChain = methodInterceptorChain;
	}
	
	/**
	 * 执行器
	 */
	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		InterceptorChain interceptorChain = methodInterceptorChain.get(invocation.getMethod());
		if(interceptorChain == null){
			return invocation.proceed();
		}
		return new ProxyExtensionMethodInvocation(interceptorChain,invocation).proceed();
	}
	
}
